package mvpexample.client.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class AddOrderViewImpl extends Composite implements AddOrderView {

	private Presenter presenter;
	
	private Grid mainPanel;

	final Button button = new Button();

	final Label orderStatus = new Label();

	public AddOrderViewImpl() {

		mainPanel = new Grid(2, 1);
		
		button.setText("Add Order");
		button.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				onAddButtonClicked(event);
			}
		});

		mainPanel.setWidget(0, 0, button);
		
		orderStatus.setText("");

		mainPanel.setWidget(1, 0, orderStatus);

		button.setFocus(true);

		initWidget(mainPanel);
	}

	@Override
	public void setPresenter(
			AddOrderView.Presenter presenter) {
		this.presenter = presenter;
	}

	void onAddButtonClicked(ClickEvent event) {
		if (presenter != null) {
			presenter.onAddButtonClicked();
		}
	}

	@Override
	public void setData(String data) {
		orderStatus.setText(data);
	}

	@Override
	public Widget asWidget() {
		return this;
	}
}
